home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mfs055 / fixup.c < prev    next >
C/C++ Source or Header  |  1991-11-19  |  2KB  |  128 lines

  1. /* Minix fixup , a quick hack to permit MINIX partitions to be (hopefully)
  2.  * read by older versions of AHDI with a MiNT minix.xfs combination.
  3.  */
  4.  
  5. /* This program was written by S N Henson in November 1991 and is released
  6.  * into the public domain. Do what you want with it . If you want to be nice
  7.  * keep my name attached to it, please.
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <fcntl.h>
  12. #include <stdio.h>
  13.  
  14. unsigned buf[512];
  15.  
  16. unsigned char *bfr=(unsigned char *)buf;
  17.  
  18. /* Change these lines if the magic number ever changes */
  19.  
  20. #define MAGIC_V1 0x137f
  21.  
  22. #define MAGIC_V2 0x2468
  23.  
  24. main(argc,argv)
  25. int argc;
  26. char **argv;
  27. {
  28.     int fd,i;
  29.     char *fnam;
  30.     int force;
  31.  
  32.     if(argc!=2 && argc!=3)
  33.     {
  34.         fprintf(stderr,"Usage : %s [-f] (device)\n",argv[0]);
  35.         exit(1);
  36.     }
  37.  
  38.     if(argc==3)
  39.     {
  40.         if(strcmp(argv[1],"-f"))
  41.         {
  42.             fprintf(stderr,"Invalid option %s\n",argv[2]);
  43.             exit(1);
  44.         }
  45.         fnam=argv[2];
  46.         force=1;
  47.     }
  48.     else
  49.     {
  50.         fnam=argv[1];
  51.         force=0;
  52.     }
  53.  
  54.     fd=open(fnam,O_RDWR);
  55.     if(fd<0)
  56.     {
  57.         fprintf(stderr,"Cant open %s\n",argv[1]);
  58.         exit(1);
  59.     }
  60.  
  61.     /* OK , seek and read in the super block */
  62.  
  63.     lseek(fd,1024l,0);
  64.     read(fd,buf,1024);
  65.     
  66.     if( (buf[8]!=MAGIC_V1) && (buf[8]!=MAGIC_V2) )
  67.     {
  68.         fprintf(stderr,"Fatal , invalid super block magic number\n");
  69.         exit(1);
  70.     }
  71.  
  72.     /* Now read in the boot block and check sector size */
  73.  
  74.     lseek(fd,0l,0);
  75.     read(fd,buf,512);
  76.     
  77.     if(bfr[11]!=0 || bfr[12]!=2)
  78.     {
  79.  
  80.         if(force)
  81.         {
  82.             bfr[11]=0;
  83.             bfr[12]=2;
  84.         }
  85.         else
  86.         {
  87.             fprintf(stderr,"Sector size not 512 bytes.\n");
  88.             fprintf(stderr,"Use the -f option to force sector\n");
  89.             fprintf(stderr,"size to 512 if you really want to do this.\n");
  90.             exit(1);
  91.         }
  92.     }
  93.  
  94.     /* 1 sector per FAT */
  95.     bfr[22]=1;
  96.     bfr[23]=0;
  97.  
  98.     /* 2 FATs */
  99.     bfr[16]=2;
  100.  
  101.     /* 16 root dir entries==1 sector */
  102.     bfr[17]=16;
  103.     bfr[18]=0;
  104.  
  105.     /* write it out */
  106.     lseek(fd,0l,0);
  107.     write(fd,buf,512);
  108.  
  109.     /* Clear buffer and setup pseudo root directory */
  110.  
  111.     bzero(bfr,512);
  112.  
  113.     /* Fill up the pseudo root dir with volume labels */
  114.     for(i=0;i<16;i++)
  115.     {
  116.         strcpy(&bfr[i<<5],"MINIXFS");
  117.         bfr[11+(i<<5)]=0x08;
  118.     }
  119.  
  120.     /* Finally write it out */
  121.     lseek(fd,1536l,0);
  122.     write(fd,buf,512);
  123.  
  124.     close(fd);
  125.  
  126.     exit(0);
  127. }
  128.